package work20241226;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zdl
 * @date 2024/12/26
 */
public class Demo20 {
    public static void main(String[] args) {
        //20. 创建一个自定义线程池，核心线程数为2，最大线程数为5，线程空闲时间为1分钟，工作队列容量为5。提交10个任务到线程池，每个任务打印当前线程的名称
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(2, 5, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(5));
        for (int i = 0; i < 10; i++) {
            poolExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名儿:"+Thread.currentThread().getName());
                }
            });
        }
    }
}
